<?php
/**
 * Created by PhpStorm.
 * User: huyang
 * Date: 2017/6/5
 * Time: 下午8:39
 */
class Manager_model extends BS_Model
{
    private $tableName = 'admin_users';
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    // 注册新增
    /* uid          用户id
     * password     密码
     * timeline     注册时间
     * ip           ip 地址（注册时可为空）
      */
    public function addManager($data) {
        $password = $data['password'];
//        $data = array(
//            'mobile' => $this->input->post('mobile'),
//            'password' => $this->input->post('password'),
//            'register_time' => date('Y-m-d H:i:s'),
//            'last_time' => date('Y-m-d H:i:s'),
//            'ip' => $ip
//        );
        $this->db->insert('admin_users', $data);
    }


    // 修改密码
    public function updatePassword($username, $password) {
        $this->db->set('password', sha1($password));
        $this->db->where('username', $username);
        $this->db->update('admin_users');
    }

    // 验证密码
    function confirmPassword($username, $password) {
        $this->db->select('*');
        $this->db->from('admin_users');
        $this->db->where('username', $username);
        $this->db->where('password', sha1($password));
        $query = $this->db->get();
        if ($query->num_rows() == 0) return null;
        return $query->row();
    }

    // 删除
    public function deleteManager($uid) {
        $this->db->where('uid',$uid);
        $this->db->delete('admin_users');
    }

    //  更新ip 和 dateline
    public function updateDateline($uid, $dateline, $ip) {
        $this->db->set('dateline', $dateline);
        $this->db->set('ip', $ip);
        $this->db->where('uid', $uid);
        $this->db->update($this->tableName);
    }
}

?>